//
//  ZBLinkmanTableViewCell.m
//  BaseRACDemo
//
//  Created by Angel_Yan on 2018/3/28.
//  Copyright © 2018年 庄波. All rights reserved.
//

#import "ZBLinkmanTableViewCell.h"
#import "ZBLinkmanItemViewModel.h"
#import "UIColor+Random.h"

@interface ZBLinkmanTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *labName;
@property (weak, nonatomic) IBOutlet UIImageView *imgVUser;
@property (weak, nonatomic) IBOutlet UILabel *labLinkman;
@property (weak, nonatomic) IBOutlet UIButton *btnSelect;
@property (weak, nonatomic) ZBLinkmanItemViewModel *viewModel;

@end


@implementation ZBLinkmanTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.labName.layer.cornerRadius = self.imgVUser.layer.cornerRadius = self.imgVUser.width/2;
    self.labName.layer.masksToBounds = self.imgVUser.layer.masksToBounds = YES;
    self.labName.textAlignment = NSTextAlignmentCenter;
    
    [RACObserve(self,viewModel.isSelect) subscribeNext:^(id  _Nullable x) {
        self.btnSelect.selected = [x boolValue];
    }];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)bindViewModel:(id)viewModel {
    
    ZBLinkmanItemViewModel *model = (ZBLinkmanItemViewModel*)viewModel;
    self.viewModel = model;
    
    self.labName.text = model.strLabName;
    self.labName.hidden = model.labNameHide;
    self.labName.backgroundColor = [UIColor RandomColor];
    
    self.imgVUser.image = model.imgPortrait;
    self.imgVUser.hidden = model.imgVHide;
    
    self.labLinkman.text = model.strLabLinkman;
    
    self.btnSelect.selected = model.isSelect;
}


@end
